import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/components/special_operation/custom_high_input_page.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/ext/widget_extension.dart';
import 'package:enterprise_v6_app/app/modules/task/task_all/security_all_fundamentals_page/clock_in/check_in/check_in_controller.dart';

/// 打卡/请假页面
class CheckInPage extends StatelessWidget {
  CheckInPage({super.key});

  final controller = Get.put(CheckInController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
      init: controller,
      builder: (_) {
        return Scaffold(
          appBar: CustomAppBar(titleText: controller.getTitle()),
          body: Column(children: [
            Container(
              color: const Color(0xffF5F5F6),
              height: 14.w,
            ),
            Expanded(
              child: Container(
                padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 16.w),
                child: controller.appClockStatus != 3 ? _getCheckInView() : _getLeaveView(),
              ),
            ),
            Container(
              color: const Color(0xffF5F5F6),
              height: 14.w,
            ),
            Container(
              color: Colors.white,
              padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 5.w),
              child: Container(
                  height: 40.w,
                  alignment: Alignment.center,
                  decoration: BoxDecoration(
                      color: const Color(0xff5C6DFF),
                      borderRadius: BorderRadius.all(
                        Radius.circular(20.w),
                      )),
                  child: Text(
                    '提交',
                    style: TextStyle(
                      fontSize: 16.sp,
                      color: const Color(0xffffffff),
                    ),
                  )).clickOnce(controller.submit),
            )
          ]),
        );
      },
    );
  }

  /// 获取打卡页面显示
  Widget _getCheckInView() {
    return Column(children: [
      Row(
        children: [
          SvgPicture.asset(
            AppImages.icon_blue_right_arrow,
          ),
          AppGaps.hGap8,
          Text(
            '打卡时间：',
            style: TextStyle(
              fontSize: 14.sp,
              height: 1.2,
              fontWeight: FontWeight.w500,
              color: const Color(0xff262F38),
            ),
          ),
          AppGaps.hGap16,
          Text(
            controller.currentTime,
            style: TextStyle(
              fontSize: 12.sp,
              height: 1.2,
              fontWeight: FontWeight.w400,
              color: const Color(0xff262F38),
            ),
          )
        ],
      ),
      CustomHighInputPage(
        title: '值班记录',
        text: controller.reason,
        onCallBack: (value) {
          controller.reason = value;
        },
        isEnabled: true,
        isShowDivider: false,
        isRequired: false,
        maxLength: 250,
      ),
    ]);
  }

  /// 获取请假页面显示
  Widget _getLeaveView() {
    return Column(children: [
      Row(
        children: [
          SvgPicture.asset(
            AppImages.icon_blue_right_arrow,
          ),
          AppGaps.hGap8,
          Text(
            '请假时间：',
            style: TextStyle(
              fontSize: 14.sp,
              height: 1.2,
              fontWeight: FontWeight.w500,
              color: const Color(0xff262F38),
            ),
          ),
          AppGaps.hGap16,
          Text(
            controller.currentPlan.classesName,
            style: TextStyle(
              fontSize: 12.sp,
              height: 1.2,
              fontWeight: FontWeight.w400,
              color: const Color(0xff33A9FF),
            ),
          ),
          AppGaps.hGap20,
          Text(
            '${controller.currentPlan.classesBeginDate.split(' ')[1]} - ${controller.currentPlan.classesEndDate.split(' ')[1]}',
            style: TextStyle(
              fontSize: 12.sp,
              height: 1.2,
              fontWeight: FontWeight.w400,
              color: const Color(0xff262F38),
            ),
          )
        ],
      ),
      CustomHighInputPage(
        title: '请假原因',
        text: controller.reason,
        onCallBack: (value) {
          controller.reason = value;
        },
        isEnabled: true,
        isShowDivider: false,
        maxLength: 250,
      ),
    ]);
  }
}
